#include "head.h"
int do_worker(int fd, MYSQL* mysql){

    char a = '\0';
    recv(fd, &a, sizeof(char), MSG_WAITALL);
printf("a: %c\n", a);

    off_t token_len = 0;
    char token[1024] = {0};
    memset(token, 0, sizeof(token));
    int ret_recv = recv(fd, &token_len, sizeof(token_len), MSG_WAITALL);
    printf("len: %ld\n", token_len);
    if(ret_recv == 0){
        return 0;
    }
    ret_recv = recv(fd, token, token_len, MSG_WAITALL);
    if(ret_recv == 0){
        return 0;
    }
    printf("token: %s\n", token);

    char user_buf[512] = {0};
    memset(user_buf, 0, sizeof(user_buf));
    free_JWT(token, user_buf);
printf("freed: token: %s\n", user_buf);

    int net_fd = atoi(strtok(user_buf, "&"));
    /* printf("tmp_fd: %s\n", tmp_fd); */

    printf("fd: %d\nnet_fd: %d\n", fd, net_fd);
    char* user_id = strtok(NULL, "&");
    /* printf("user_id: %s\n", user_id); */

    
        char token_tmp[1024] = {0};
        memset(token_tmp, 0, sizeof(token_tmp));
//printf("is here!\n");
        make_JWT(token_tmp, fd, user_id);
printf("token: %s\n", token_tmp);
        token_len = strlen(token_tmp);
        send(fd, &token_len, sizeof(off_t), MSG_NOSIGNAL);
        send(fd, token_tmp, token_len, MSG_NOSIGNAL);
printf("%ld: %s\n", token_len, token_tmp);


    if(a == '%'){
        printf("put_server\n");
        put_server(fd, mysql);
    }else{
        printf("snd_cmd\n");
        snd_cmd(fd, mysql);
    }
    printf("done!\n");


    return 0;
}
